﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SzCourt.Logic.BLL;
using KMFrame.Permission.Util;

namespace SzCourt.WebSite.reporter
{
    public partial class success : System.Web.UI.Page
    {
        private string _Name = string.Empty;
        private string _Password = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                getParam();
                if (this._Name.Length > 0 && this._Password.Length > 0)
                {
                    userlogin();
                }
                else
                {
                    Response.Redirect("/reporter/login.aspx?tag=1");
                }
            }
        }

        //获取参数值
        private void getParam()
        {
            this._Name = string.IsNullOrEmpty(Request.Form["txtName"]) ? "" : Request.Form["txtName"];
            this._Password = string.IsNullOrEmpty(Request.Form["txtPassword"]) ? "" : Request.Form["txtPassword"];
        }

        //登录
        private void userlogin()
        {
            SzCourt.Logic.BLL.UserInfo bll = new SzCourt.Logic.BLL.UserInfo();
            PUserInfo result = (PUserInfo)bll.Login(this._Name, this._Password);

            if (result != null)
            {
                if (result.UserType.GetValueOrDefault(0) == UserTypes.REPORTS)
                {
                    UserSession user = new UserSession(result.UserID, result.UserName, result.UserGUID);
                    SessionBox.CreateUserSession(user);
                    Response.Redirect("/reporter/index.aspx");
                }
                else
                {
                    this.spMessage.InnerHtml = "不是授权用户，不能登录记者之家！";
                }
            }
            else
            {
                //this.spMessage.InnerHtml = "登录失败，请检查用户和密码是否正确，并重新登录！";
            }
        }
    }
}
